<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span class="hs-cpp">
#include &quot;containers.h&quot;
</span><span class="hs-pragma">{-# OPTIONS_HADDOCK hide #-}</span><span>
</span><span id="line-4"></span><span>
</span><span id="line-5"></span><span class="hs-comment">-- | A clone of Control.Monad.State.Strict.</span><span>
</span><span id="line-6"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Utils.Containers.Internal.State</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-7"></span><span>
</span><span id="line-8"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Prelude.html#"><span class="hs-identifier">Prelude</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="hs-cpp">
#if MIN_VERSION_base(4,8,0)
</span><span>    </span><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier">Applicative</span></a></span><span class="hs-cpp">
#endif
</span><span>    </span><span class="hs-special">)</span><span>
</span><span id="line-13"></span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Base.html#ap"><span class="hs-identifier">ap</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Applicative.html#"><span class="hs-identifier">Control.Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier">Applicative</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#liftA"><span class="hs-identifier">liftA</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-keyword">newtype</span><span> </span><span id="State"><span class="annot"><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-var">State</span></a></span></span><span> </span><span id="local-6989586621679158530"><span class="annot"><a href="#local-6989586621679158530"><span class="hs-identifier hs-type">s</span></a></span></span><span> </span><span id="local-6989586621679158529"><span class="annot"><a href="#local-6989586621679158529"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="State"><span class="annot"><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-var">State</span></a></span></span><span> </span><span class="hs-special">{</span><span id="runState"><span class="annot"><span class="annottext">forall s a. State s a -&gt; s -&gt; (s, a)
</span><a href="Utils.Containers.Internal.State.html#runState"><span class="hs-identifier hs-var hs-var">runState</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679158530"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679158530"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679158529"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">}</span><span>
</span><span id="line-18"></span><span>
</span><span id="line-19"></span><span id="local-6989586621679158521"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679158464"><span class="annot"><a href="../../base/src/GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-type">State</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679158521"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-20"></span><span>    </span><span id="local-6989586621679158461"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; State s a -&gt; State s b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; State s a -&gt; State s b
forall (f :: * -&gt; *) a b. Applicative f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#liftA"><span class="hs-identifier hs-var">liftA</span></a></span></span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span id="local-6989586621679158508"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679158456"><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-type">State</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679158508"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-23"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#return"><span class="hs-pragma hs-type">return</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-24"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="hs-pragma">(</span><span class="hs-pragma">&gt;&gt;=</span><span class="hs-pragma">)</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-25"></span><span>    </span><span id="local-6989586621679158452"><span class="annot"><span class="annottext">return :: forall a. a -&gt; State s a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var hs-var hs-var hs-var">return</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; State s a
forall (f :: * -&gt; *) a. Applicative f =&gt; a -&gt; f a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var">pure</span></a></span><span>
</span><span id="line-26"></span><span>    </span><span id="local-6989586621679158451"><span class="annot"><span class="annottext">State s a
</span><a href="#local-6989586621679158451"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679158450"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b. State s a -&gt; (a -&gt; State s b) -&gt; State s b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span id="local-6989586621679158449"><span class="annot"><span class="annottext">a -&gt; State s b
</span><a href="#local-6989586621679158449"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, b)) -&gt; State s b
forall s a. (s -&gt; (s, a)) -&gt; State s a
</span><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-var">State</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, b)) -&gt; State s b) -&gt; (s -&gt; (s, b)) -&gt; State s b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679158448"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158448"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State s a -&gt; s -&gt; (s, a)
forall s a. State s a -&gt; s -&gt; (s, a)
</span><a href="Utils.Containers.Internal.State.html#runState"><span class="hs-identifier hs-var hs-var">runState</span></a></span><span> </span><span class="annot"><span class="annottext">State s a
</span><a href="#local-6989586621679158451"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158448"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-27"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621679158447"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158447"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679158446"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679158446"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">State s b -&gt; s -&gt; (s, b)
forall s a. State s a -&gt; s -&gt; (s, a)
</span><a href="Utils.Containers.Internal.State.html#runState"><span class="hs-identifier hs-var hs-var">runState</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; State s b
</span><a href="#local-6989586621679158449"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679158446"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158447"><span class="hs-identifier hs-var">s'</span></a></span></span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span id="local-6989586621679158520"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679158436"><span id="local-6989586621679158438"><span id="local-6989586621679158440"><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-type">State</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679158520"><span class="hs-identifier hs-type">s</span></a></span><span class="hs-special">)</span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-30"></span><span>    </span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#pure"><span class="hs-pragma hs-type">pure</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-31"></span><span>    </span><span id="local-6989586621679158434"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; State s a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621679158433"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679158433"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s -&gt; (s, a)) -&gt; State s a
forall s a. (s -&gt; (s, a)) -&gt; State s a
</span><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-var">State</span></a></span><span> </span><span class="annot"><span class="annottext">((s -&gt; (s, a)) -&gt; State s a) -&gt; (s -&gt; (s, a)) -&gt; State s a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679158432"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158432"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158432"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679158433"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-32"></span><span>    </span><span id="local-6989586621679158430"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. State s (a -&gt; b) -&gt; State s a -&gt; State s b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;*&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">State s (a -&gt; b) -&gt; State s a -&gt; State s b
forall (m :: * -&gt; *) a b. Monad m =&gt; m (a -&gt; b) -&gt; m a -&gt; m b
</span><a href="../../base/src/GHC.Base.html#ap"><span class="hs-identifier hs-var">ap</span></a></span></span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span id="local-6989586621679158483"><span id="local-6989586621679158484"><span class="annot"><a href="Utils.Containers.Internal.State.html#execState"><span class="hs-identifier hs-type">execState</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Utils.Containers.Internal.State.html#State"><span class="hs-identifier hs-type">State</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679158484"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679158483"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679158484"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679158483"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-35"></span><span id="execState"><span class="annot"><span class="annottext">execState :: forall s a. State s a -&gt; s -&gt; a
</span><a href="Utils.Containers.Internal.State.html#execState"><span class="hs-identifier hs-var hs-var">execState</span></a></span></span><span> </span><span id="local-6989586621679158428"><span class="annot"><span class="annottext">State s a
</span><a href="#local-6989586621679158428"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679158427"><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158427"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(s, a) -&gt; a
forall a b. (a, b) -&gt; b
</span><a href="../../base/src/Data.Tuple.html#snd"><span class="hs-identifier hs-var">snd</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">State s a -&gt; s -&gt; (s, a)
forall s a. State s a -&gt; s -&gt; (s, a)
</span><a href="Utils.Containers.Internal.State.html#runState"><span class="hs-identifier hs-var hs-var">runState</span></a></span><span> </span><span class="annot"><span class="annottext">State s a
</span><a href="#local-6989586621679158428"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">s
</span><a href="#local-6989586621679158427"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-36"></span></pre></body></html>